/*
Project:				Perry Intergenerational
Author:					Victor Ronda
Original Date:			January 21, 2022
*/



*---------------------------------------*
*  Computing the Table #2 in the Paper  *
*---------------------------------------*



*** Setting environment and filepaths ***
global klmshare : env klmshare
global klmperry : env klmperry
global emp $klmperry/multigen_revision/Empirics

*---------------------------- Loading Results -----------------------------*

use $emp/Results/estimates_participants.dta, clear
append using $emp/Results/asym_pval_participants.dta
append using $emp/Results/perm_pval_participants.dta
append using $emp/Results/boot_pval_participants.dta


local l_vname1_fbirth_55 "Age when Child Born"
local l_vname1_fbirth20_35 "Age 20 to 35 when Child Born"
local l_vname1_any_outwed_55 "Out of Wedlock when Child Born"
local l_vname1_any_cohab "Cohabitated when Child Grew up"
local l_vname1_smpar10_2 "Married through Child's Age 10"
local l_vname1_dailyread_child_55 "Read Daily to Child"
local l_vname1_rhs_55 "High School Graduation"
local l_vname1_col_55 "College Graduation"
local l_vname1_emp110_3 "Fraction of Years Employed"
local l_vname1_earn110_3 "Income (1,000s of 2017 dollars)"
local l_vname1_s_mjail_any50 "Days in Jail"
local l_vname1_s_marr_vio50 "Misdemeanor Arrests"
local l_vname1_s_fpar_vio50 "Felony Arrests"
local l_vname1_gint "Executive Functioning"
local l_vname1_postrait1 "Positive Personality"
local l_vname1_grit "Grit"
local l_vname1_risktaking "Openness to Experiences"
local l_vname1_stablemar_21_40 "Married Ages 21-40"
local l_vname1_earn_21_40 "Income Ages 21-40 (1,000s of 2017 dollars)"
local l_vname1_lat_health "Latent Health"
local l_vname1_lat_health80 "Latent Health at 80th Percentile"


global vlist fbirth_55 fbirth20_35 any_outwed_55 any_cohab stablemar_21_40 smpar10_2 dailyread_child_55 rhs_55 col_55 emp110_3 earn_21_40 earn110_3 s_mjail_any50 s_marr_vio50 s_fpar_vio50 gint postrait1 grit risktaking  lat_health lat_health80



* first row
sum fbirth_55_aipwd_2 if _n==1
sum fbirth_55_aipwse_2 if _n==4
sum fbirth_55_aipwd_2 if _n==2
sum fbirth_55_aipwd_2 if _n==3
sum fbirth_55_aipwd_2 if _n==4
sum fbirth_55_aipwt_2 if _n==4

* second row
sum fbirth_55_udimd_2 if _n==1
sum fbirth_55_udimse_2 if _n==4
sum fbirth_55_colsd_2 if _n==1
sum fbirth_55_colsse_2 if _n==4
sum fbirth_55_lblld_2 if _n==4
sum fbirth_55_lbuld_2 if _n==4


file open latex_table using "$emp/Tables/tab_main_participants_1.tex", write replace
foreach dvar in $vlist {

*** First Line ***

* Name
local `dvar'_line1 "`l_vname1_`dvar'' "

* Estimate
local e_estm = `dvar'_aipwd_2[1]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & $ `: di %5.3f ``estm'' ' $"

* Bootstrap Standard Error
local e_estm = `dvar'_aipwse_2[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & ($ `: di %5.3f ``estm'' ' $)"

* Analytic P-val
local e_estm = `dvar'_aipwd_2[2]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Permutation P-val
local e_estm = `dvar'_aipwd_2[3]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Bootstrap P-val
local e_estm = `dvar'_aipwd_2[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

* Bootstrap-t P-val
local e_estm = `dvar'_aipwt_2[4]
local estm "e_estm"
local `dvar'_line1 "``dvar'_line1' & [$ `: di %5.3f ``estm'' ' $]"

}
foreach dvar in $vlist {
	file write latex_table "``dvar'_line1' \\" _n
}
file close latex_table


sum fbirth_55_udimd_2 if _n==1
sum fbirth_55_udimse_2 if _n==4
sum fbirth_55_colsd_2 if _n==1
sum fbirth_55_colsse_2 if _n==4
sum fbirth_55_lblld_2 if _n==4
sum fbirth_55_lbuld_2 if _n==4

file open latex_table using "$emp/Tables/tab_main_participants_2.tex", write replace
foreach dvar in $vlist {

*** Second Line ***
* Name
local `dvar'_line2 "`l_vname1_`dvar'' "

* Mean Differences
local e_estm = `dvar'_udimd_2[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* Mean Differences SE
local e_estm = `dvar'_udimse_2[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & ($ `: di %5.3f ``estm'' ' $)"

* OLS
local e_estm = `dvar'_colsd_2[1]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* OLS SE
local e_estm = `dvar'_colsse_2[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & ($ `: di %5.3f ``estm'' ' $)"

* Lee bounds - lower
local e_estm = `dvar'_lblld_2[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"

* Lee bounds - upper
local e_estm = `dvar'_lbuld_2[4]
local estm "e_estm"
local `dvar'_line2 "``dvar'_line2' & $ `: di %5.3f ``estm'' ' $"
}

foreach dvar in $vlist {
	file write latex_table "``dvar'_line2' \\" _n
}
file close latex_table

